CREATE VIEW [dbo].[Order_Total]
AS
SELECT        Order_ID, SUM(Price) AS Total
FROM            dbo.Order_Detail
GROUP BY Order_ID

GO
CREATE PROC TC(
	@Date_Begin DateTime,
	@Date_End DateTime
)
AS
BEGIN
	SELECT Q1.ID,Q1.Order_Type,
		Case
			WHEN Q1.Order_Type>127 THEN Q2.Total*-1
			ELSE Q2.Total
		END As Total
	FROM [Order] AS Q1
	INNER JOIN Order_Total AS Q2 ON Q2.Order_ID=Q1.ID
	WHERE Q1.Date_T>@Date_Begin AND Q1.Date_T<@Date_End
END
GO